package com.wish.g1.common.core.config;

import com.zhenzi.sms.ZhenziSmsClient;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class SmsConfig {

    public static ZhenziSmsClient zhenziSmsClient;

    public SmsConfig() {
        zhenziSmsClient=new ZhenziSmsClient(APIURL, APPID, APPSECRET);
    }

    public static ZhenziSmsClient  getZhenziSmsClient() {
        return zhenziSmsClient;
    }

    public static String APPID="111292";
    public static String APPSECRET="f7ab991d-1ae0-4d51-b9bf-8bf5716316bf";
    public static String APIURL="https://sms_developer.zhenzikj.com";
    public static int TEMPLATEID=8771;

    public static String send(String phone,String code) throws Exception {
        Map<String,Object> params=new HashMap<>();
        params.put("number",phone);
        // 修改为自己的templateId
        params.put("templateId", TEMPLATEID);
        System.err.println("验证码是============="+code);
        String[] templateParams = new String[2];
        templateParams[0] = code;
        templateParams[1] = "2分钟";
        params.put("templateParams", templateParams);
        String result = SmsConfig.zhenziSmsClient.send(params);
        return result;
    }

    public static String send2(String phone,String msg) throws Exception {
        Map<String,Object> params=new HashMap<>();
        params.put("number",phone);
        // 修改为自己的templateId
        params.put("templateId", TEMPLATEID);
        String[] templateParams = new String[2];
        templateParams[0] = msg;
        templateParams[1] = "2分钟";
        params.put("templateParams", templateParams);
        String result = SmsConfig.zhenziSmsClient.send(params);
        return result;
    }

}
